package 字符串算法.回文串;

import java.util.HashSet;

public class 最长回文串 {

    public int longestPalindrome(String s){
       if (s.length() == 0){
           return 0;

       }
       //用于存放地址
        HashSet<Character> hashSet = new HashSet<>();
        char[] chars = s.toCharArray();
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (!hashSet.contains(chars[i])){
                hashSet.add(chars[i]);
            }else{
                hashSet.remove(chars[i]);
                count++;
            }
        }
        return hashSet.isEmpty()?count*2:count*2+1;
    }
}
